#ifndef LIGHT_H
#define LIGHT_H

#include "Vector.h"
#include "Color.h"
class Light{

public: 
	Vector position,Direction;
	Color color;
	float radius;
	Light(): position(0,0,0), color(1,1,1,0){}
	Light(const Vector &p,const Vector &d,const Color &c,const float &r): position(p), Direction(d), color(c),radius(r){}

	float SpotLightArea(Ray ray,Vector sphere_center,float x, float y)	{		
		float a = 1; // normalized
		float b = 2*(((ray.origin.x-sphere_center.x)*ray.Direction.x)+((ray.origin.y-sphere_center.y)*ray.Direction.y)+((ray.origin.z-sphere_center.z)*ray.Direction.z));
		float c = pow(ray.origin.x-sphere_center.x, 2) + pow(ray.origin.y-sphere_center.y, 2) + pow(ray.origin.z-sphere_center.z, 2) - (radius*radius);
		float discriminant = b*b - 4*c;
		/*
		float in_circle = ray.Direction.x*ray.Direction.x+ray.Direction.y*ray.Direction.y-radius*radius;
		if(in_circle>0)
			return false;
		else
			return true;
		*/
		if (discriminant > 0) {
			/// the ray intersects the sphere
			
			// the first root
			float root_1 = ((-1*b - sqrt(discriminant))/2) - 0.000001;
			
			if (root_1 > 0) {
				// the first root is the smallest positive root
				return root_1;
			}
			else {
				// the second root is the smallest positive root
				float root_2 = ((sqrt(discriminant) - b)/2) - 0.000001;
				return root_2;
			}
		}
		else 
			// the ray missed the sphere
			return -1;

		}	
	
	
	
};

#endif


